package blender.makesdna.sdna;

import java.nio.ByteBuffer;
import java.util.Map;
import java.util.HashMap;

public class DNATools {
  public static int pointerSize = 4;
  private static Map<Integer, Object> pointerMap = new HashMap<Integer, Object>();
  public static Class getClassType(int SDNAnr) {
    switch (SDNAnr) {
      case 0: return Link.class;
      case 1: return LinkData.class;
      case 2: return ListBase.class;
      case 3: return vec2s.class;
      case 4: return vec2f.class;
      case 5: return rcti.class;
      case 6: return rctf.class;
      case 7: return IDPropertyData.class;
      case 8: return IDProperty.class;
      case 9: return ID.class;
      case 10: return Library.class;
      case 11: return PreviewImage.class;
      case 12: return IpoDriver.class;
      case 13: return IpoCurve.class;
      case 14: return Ipo.class;
      case 15: return KeyBlock.class;
      case 16: return Key.class;
      case 17: return TextLine.class;
      case 18: return TextMarker.class;
      case 19: return Text.class;
      case 20: return PackedFile.class;
      case 21: return Camera.class;
      case 22: return ImageUser.class;
      case 23: return Image.class;
      case 24: return MTex.class;
      case 25: return PluginTex.class;
      case 26: return CBData.class;
      case 27: return ColorBand.class;
      case 28: return EnvMap.class;
      case 29: return PointDensity.class;
      case 30: return VoxelData.class;
      case 31: return Tex.class;
      case 32: return TexMapping.class;
      case 33: return Lamp.class;
      case 34: return VolumeSettings.class;
      case 35: return Material.class;
      case 36: return VFont.class;
      case 37: return MetaElem.class;
      case 38: return MetaBall.class;
      case 39: return BezTriple.class;
      case 40: return BPoint.class;
      case 41: return Nurb.class;
      case 42: return CharInfo.class;
      case 43: return TextBox.class;
      case 44: return EditNurb.class;
      case 45: return Curve.class;
      case 46: return Mesh.class;
      case 47: return TFace.class;
      case 48: return MFace.class;
      case 49: return MEdge.class;
      case 50: return MDeformWeight.class;
      case 51: return MDeformVert.class;
      case 52: return MVert.class;
      case 53: return MCol.class;
      case 54: return MTexPoly.class;
      case 55: return MLoopUV.class;
      case 56: return MLoopCol.class;
      case 57: return MSticky.class;
      case 58: return MSelect.class;
      case 59: return MTFace.class;
      case 60: return MFloatProperty.class;
      case 61: return MIntProperty.class;
      case 62: return MStringProperty.class;
      case 63: return OrigSpaceFace.class;
      case 64: return MDisps.class;
      case 65: return MultiresCol.class;
      case 66: return MultiresColFace.class;
      case 67: return MultiresFace.class;
      case 68: return MultiresEdge.class;
      case 69: return MultiresLevel.class;
      case 70: return Multires.class;
      case 71: return PartialVisibility.class;
      case 72: return ModifierData.class;
      case 73: return SubsurfModifierData.class;
      case 74: return LatticeModifierData.class;
      case 75: return CurveModifierData.class;
      case 76: return BuildModifierData.class;
      case 77: return MaskModifierData.class;
      case 78: return ArrayModifierData.class;
      case 79: return MirrorModifierData.class;
      case 80: return EdgeSplitModifierData.class;
      case 81: return BevelModifierData.class;
      case 82: return BMeshModifierData.class;
      case 83: return SmokeModifierData.class;
      case 84: return DisplaceModifierData.class;
      case 85: return UVProjectModifierData.class;
      case 86: return DecimateModifierData.class;
      case 87: return SmoothModifierData.class;
      case 88: return CastModifierData.class;
      case 89: return WaveModifierData.class;
      case 90: return ArmatureModifierData.class;
      case 91: return HookModifierData.class;
      case 92: return SoftbodyModifierData.class;
      case 93: return ClothModifierData.class;
      case 94: return CollisionModifierData.class;
      case 95: return SurfaceModifierData.class;
      case 96: return BooleanModifierData.class;
      case 97: return MDefInfluence.class;
      case 98: return MDefCell.class;
      case 99: return MeshDeformModifierData.class;
      case 100: return ParticleSystemModifierData.class;
      case 101: return ParticleInstanceModifierData.class;
      case 102: return ExplodeModifierData.class;
      case 103: return MultiresModifierData.class;
      case 104: return FluidsimModifierData.class;
      case 105: return ShrinkwrapModifierData.class;
      case 106: return SimpleDeformModifierData.class;
      case 107: return ShapeKeyModifierData.class;
      case 108: return SolidifyModifierData.class;
      case 109: return ScrewModifierData.class;
      case 110: return EditLatt.class;
      case 111: return Lattice.class;
      case 112: return bDeformGroup.class;
      case 113: return BoundBox.class;
      case 114: return bObject.class;
      case 115: return ObHook.class;
      case 116: return DupliObject.class;
      case 117: return PartDeflect.class;
      case 118: return EffectorWeights.class;
      case 119: return PTCacheExtra.class;
      case 120: return PTCacheMem.class;
      case 121: return PointCache.class;
      case 122: return SBVertex.class;
      case 123: return BulletSoftBody.class;
      case 124: return SoftBody.class;
      case 125: return FluidsimSettings.class;
      case 126: return World.class;
      case 127: return Base.class;
      case 128: return AviCodecData.class;
      case 129: return QuicktimeCodecData.class;
      case 130: return QuicktimeCodecSettings.class;
      case 131: return FFMpegCodecData.class;
      case 132: return AudioData.class;
      case 133: return SceneRenderLayer.class;
      case 134: return RenderData.class;
      case 135: return RenderProfile.class;
      case 136: return GameDome.class;
      case 137: return GameFraming.class;
      case 138: return GameData.class;
      case 139: return TimeMarker.class;
      case 140: return Paint.class;
      case 141: return ImagePaintSettings.class;
      case 142: return ParticleBrushData.class;
      case 143: return ParticleEditSettings.class;
      case 144: return TransformOrientation.class;
      case 145: return Sculpt.class;
      case 146: return VPaint.class;
      case 147: return ToolSettings.class;
      case 148: return bStats.class;
      case 149: return UnitSettings.class;
      case 150: return PhysicsSettings.class;
      case 151: return Scene.class;
      case 152: return BGpic.class;
      case 153: return RegionView3D.class;
      case 154: return View3D.class;
      case 155: return View2D.class;
      case 156: return SpaceLink.class;
      case 157: return SpaceInfo.class;
      case 158: return SpaceIpo.class;
      case 159: return SpaceButs.class;
      case 160: return SpaceSeq.class;
      case 161: return FileSelectParams.class;
      case 162: return SpaceFile.class;
      case 163: return SpaceOops.class;
      case 164: return SpaceImage.class;
      case 165: return SpaceNla.class;
      case 166: return SpaceText.class;
      case 167: return Script.class;
      case 168: return SpaceScript.class;
      case 169: return SpaceTimeCache.class;
      case 170: return SpaceTime.class;
      case 171: return SpaceNode.class;
      case 172: return SpaceLogic.class;
      case 173: return SpaceImaSel.class;
      case 174: return ConsoleLine.class;
      case 175: return SpaceConsole.class;
      case 176: return SpaceUserPref.class;
      case 177: return SpaceSound.class;
      case 178: return uiFont.class;
      case 179: return uiFontStyle.class;
      case 180: return uiStyle.class;
      case 181: return uiWidgetColors.class;
      case 182: return uiWidgetStateColors.class;
      case 183: return ThemeUI.class;
      case 184: return ThemeSpace.class;
      case 185: return ThemeWireColor.class;
      case 186: return bTheme.class;
      case 187: return bAddon.class;
      case 188: return SolidLight.class;
      case 189: return UserDef.class;
      case 190: return bScreen.class;
      case 191: return ScrVert.class;
      case 192: return ScrEdge.class;
      case 193: return Panel.class;
      case 194: return ScrArea.class;
      case 195: return ARegion.class;
      case 196: return FileGlobal.class;
      case 197: return StripElem.class;
      case 198: return StripCrop.class;
      case 199: return StripTransform.class;
      case 200: return StripColorBalance.class;
      case 201: return StripProxy.class;
      case 202: return Strip.class;
      case 203: return PluginSeq.class;
      case 204: return Sequence.class;
      case 205: return MetaStack.class;
      case 206: return Editing.class;
      case 207: return WipeVars.class;
      case 208: return GlowVars.class;
      case 209: return TransformVars.class;
      case 210: return SolidColorVars.class;
      case 211: return SpeedControlVars.class;
      case 212: return Effect.class;
      case 213: return BuildEff.class;
      case 214: return PartEff.class;
      case 215: return WaveEff.class;
      case 216: return TreeStoreElem.class;
      case 217: return TreeStore.class;
      case 218: return bProperty.class;
      case 219: return bNearSensor.class;
      case 220: return bMouseSensor.class;
      case 221: return bTouchSensor.class;
      case 222: return bKeyboardSensor.class;
      case 223: return bPropertySensor.class;
      case 224: return bActuatorSensor.class;
      case 225: return bDelaySensor.class;
      case 226: return bCollisionSensor.class;
      case 227: return bRadarSensor.class;
      case 228: return bRandomSensor.class;
      case 229: return bRaySensor.class;
      case 230: return bArmatureSensor.class;
      case 231: return bMessageSensor.class;
      case 232: return bSensor.class;
      case 233: return bJoystickSensor.class;
      case 234: return bExpressionCont.class;
      case 235: return bPythonCont.class;
      case 236: return bController.class;
      case 237: return bAddObjectActuator.class;
      case 238: return bActionActuator.class;
      case 239: return Sound3D.class;
      case 240: return bSoundActuator.class;
      case 241: return bEditObjectActuator.class;
      case 242: return bSceneActuator.class;
      case 243: return bPropertyActuator.class;
      case 244: return bObjectActuator.class;
      case 245: return bIpoActuator.class;
      case 246: return bCameraActuator.class;
      case 247: return bConstraintActuator.class;
      case 248: return bGroupActuator.class;
      case 249: return bRandomActuator.class;
      case 250: return bMessageActuator.class;
      case 251: return bGameActuator.class;
      case 252: return bVisibilityActuator.class;
      case 253: return bTwoDFilterActuator.class;
      case 254: return bParentActuator.class;
      case 255: return bStateActuator.class;
      case 256: return bArmatureActuator.class;
      case 257: return bActuator.class;
      case 258: return bSound.class;
      case 259: return GroupObject.class;
      case 260: return Group.class;
      case 261: return Bone.class;
      case 262: return bArmature.class;
      case 263: return bMotionPathVert.class;
      case 264: return bMotionPath.class;
      case 265: return bAnimVizSettings.class;
      case 266: return bPoseChannel.class;
      case 267: return bPose.class;
      case 268: return bIKParam.class;
      case 269: return bItasc.class;
      case 270: return bActionGroup.class;
      case 271: return bAction.class;
      case 272: return bDopeSheet.class;
      case 273: return SpaceAction.class;
      case 274: return bActionChannel.class;
      case 275: return bConstraintChannel.class;
      case 276: return bConstraint.class;
      case 277: return bConstraintTarget.class;
      case 278: return bPythonConstraint.class;
      case 279: return bKinematicConstraint.class;
      case 280: return bSplineIKConstraint.class;
      case 281: return bTrackToConstraint.class;
      case 282: return bRotateLikeConstraint.class;
      case 283: return bLocateLikeConstraint.class;
      case 284: return bSizeLikeConstraint.class;
      case 285: return bSameVolumeConstraint.class;
      case 286: return bTransLikeConstraint.class;
      case 287: return bMinMaxConstraint.class;
      case 288: return bActionConstraint.class;
      case 289: return bLockTrackConstraint.class;
      case 290: return bDampTrackConstraint.class;
      case 291: return bFollowPathConstraint.class;
      case 292: return bStretchToConstraint.class;
      case 293: return bRigidBodyJointConstraint.class;
      case 294: return bClampToConstraint.class;
      case 295: return bChildOfConstraint.class;
      case 296: return bTransformConstraint.class;
      case 297: return bPivotConstraint.class;
      case 298: return bLocLimitConstraint.class;
      case 299: return bRotLimitConstraint.class;
      case 300: return bSizeLimitConstraint.class;
      case 301: return bDistLimitConstraint.class;
      case 302: return bShrinkwrapConstraint.class;
      case 303: return bActionModifier.class;
      case 304: return bActionStrip.class;
      case 305: return bNodeStack.class;
      case 306: return bNodeSocket.class;
      case 307: return bNodePreview.class;
      case 308: return bNode.class;
      case 309: return bNodeLink.class;
      case 310: return bNodeTree.class;
      case 311: return NodeImageAnim.class;
      case 312: return NodeBlurData.class;
      case 313: return NodeDBlurData.class;
      case 314: return NodeBilateralBlurData.class;
      case 315: return NodeHueSat.class;
      case 316: return NodeImageFile.class;
      case 317: return NodeChroma.class;
      case 318: return NodeTwoXYs.class;
      case 319: return NodeTwoFloats.class;
      case 320: return NodeGeometry.class;
      case 321: return NodeVertexCol.class;
      case 322: return NodeDefocus.class;
      case 323: return NodeScriptDict.class;
      case 324: return NodeGlare.class;
      case 325: return NodeTonemap.class;
      case 326: return NodeLensDist.class;
      case 327: return NodeColorBalance.class;
      case 328: return NodeColorspill.class;
      case 329: return TexNodeOutput.class;
      case 330: return CurveMapPoint.class;
      case 331: return CurveMap.class;
      case 332: return CurveMapping.class;
      case 333: return Histogram.class;
      case 334: return Scopes.class;
      case 335: return BrushClone.class;
      case 336: return Brush.class;
      case 337: return CustomDataLayer.class;
      case 338: return CustomDataExternal.class;
      case 339: return CustomData.class;
      case 340: return HairKey.class;
      case 341: return ParticleKey.class;
      case 342: return BoidParticle.class;
      case 343: return ParticleSpring.class;
      case 344: return ChildParticle.class;
      case 345: return ParticleTarget.class;
      case 346: return ParticleDupliWeight.class;
      case 347: return ParticleData.class;
      case 348: return SPHFluidSettings.class;
      case 349: return ParticleSettings.class;
      case 350: return ParticleSystem.class;
      case 351: return ClothSimSettings.class;
      case 352: return ClothCollSettings.class;
      case 353: return bGPDspoint.class;
      case 354: return bGPDstroke.class;
      case 355: return bGPDframe.class;
      case 356: return bGPDlayer.class;
      case 357: return bGPdata.class;
      case 358: return ReportList.class;
      case 359: return wmWindowManager.class;
      case 360: return wmWindow.class;
      case 361: return wmKeyMapItem.class;
      case 362: return wmKeyMap.class;
      case 363: return wmKeyConfig.class;
      case 364: return wmOperator.class;
      case 365: return FModifier.class;
      case 366: return FMod_Generator.class;
      case 367: return FMod_FunctionGenerator.class;
      case 368: return FCM_EnvelopeData.class;
      case 369: return FMod_Envelope.class;
      case 370: return FMod_Cycles.class;
      case 371: return FMod_Python.class;
      case 372: return FMod_Limits.class;
      case 373: return FMod_Noise.class;
      case 374: return FMod_Stepped.class;
      case 375: return DriverTarget.class;
      case 376: return DriverVar.class;
      case 377: return ChannelDriver.class;
      case 378: return FPoint.class;
      case 379: return FCurve.class;
      case 380: return AnimMapPair.class;
      case 381: return AnimMapper.class;
      case 382: return NlaStrip.class;
      case 383: return NlaTrack.class;
      case 384: return KS_Path.class;
      case 385: return KeyingSet.class;
      case 386: return AnimOverride.class;
      case 387: return AnimData.class;
      case 388: return IdAdtTemplate.class;
      case 389: return BoidRule.class;
      case 390: return BoidRuleGoalAvoid.class;
      case 391: return BoidRuleAvoidCollision.class;
      case 392: return BoidRuleFollowLeader.class;
      case 393: return BoidRuleAverageSpeed.class;
      case 394: return BoidRuleFight.class;
      case 395: return BoidData.class;
      case 396: return BoidState.class;
      case 397: return BoidSettings.class;
      case 398: return SmokeDomainSettings.class;
      case 399: return SmokeFlowSettings.class;
      case 400: return SmokeCollSettings.class;
    }
    return Object.class;
  }
  public static <T> T link(int pointer, Class<T> type) {
    if (pointer==0 || type==Object.class || type.isArray()) return null;
    if (pointerMap.containsKey(pointer)) {
      Object existing = pointerMap.get(pointer);
      if (type.isAssignableFrom(existing.getClass())) return type.cast(existing);
      else return null;
    } else {
      try {
        T temp = type.newInstance();
        pointerMap.put(pointer, temp);
        return temp;
      } catch (Exception ex) { ex.printStackTrace(); return null; }
    }
  }
  public static Integer ptr(ByteBuffer buffer) {
    int pointer = 0;
    if (pointerSize == 4) pointer = buffer.getInt();
    else if (pointerSize == 8) pointer = (int)buffer.getLong();
    return pointer;
  }
}

